package com.ae28113.adult_education.controller;

import java.util.List;

import com.ae28113.adult_education.common.PageParam;
import com.ae28113.adult_education.common.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ae28113.adult_education.domain.Student;
import com.ae28113.adult_education.service.StudentService;


/**
* @author 咋了123
*/
@RestController
@RequestMapping("/student")
public class StudentController{
@Autowired
public StudentService studentService;

@GetMapping("/{id}")
public R<Student> getById(@PathVariable Integer id){
Student student =studentService.getById(id);
return R.ok(student);
}

@GetMapping
public R<List<Student>> get(){
List<Student> list = studentService.list();
return R.ok(list);
}

@PostMapping
public R<IPage<Student>> page(@RequestBody PageParam<Student> pageParam){
//        分页
IPage<Student> page = new Page<>(pageParam.getPageNum(),pageParam.getPageSize());
QueryWrapper<Student> wrraper = new QueryWrapper<>();
//        获取查询条件
Student a = pageParam.getQuery();
if(a!=null){
//按前端筛选条件添加条件

}
return R.ok(studentService.page(page,wrraper));
}

@PostMapping("/add")
public R add(@RequestBody Student student){
studentService.save(student);
return R.ok();
}

@PostMapping("/edit")
public R edit(@RequestBody Student student){
studentService.updateById(student);
return R.ok();
}

@GetMapping("/delete/{id}")
public R delete(@PathVariable Integer id){
studentService.removeById(id);
return R.ok();
}
}




